package com.lyx.db137.controller;

import com.lyx.db137.common.R;
import com.lyx.db137.entity.Menu;
import com.lyx.db137.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: zero domain
 * @CreateTime: 2024/12/30 9:00
 * @Description: TODO
 * @Version: 1.0
 */
@CrossOrigin(origins = "*")
@RestController
public class MenuController {
    @Autowired
    MenuService menuService;

    /**
     * 获取所有菜单
     * @return
     */
    @GetMapping("selectMenu")
    public R selectMenu(){
        List<Menu> menuList = this.menuService.list();
        return new R().add("menuList",menuList);
    }

    /**
     * 根据id获取一个menu对象
     * @return
     */
    @GetMapping("selectMenuByid/{id}")
    public R selectMenuByid(@PathVariable("id")int  id){
        Menu menu = this.menuService.getById(id);
        return new R().add("menu",menu);
    }
}
